home *** CD-ROM | disk | FTP | other *** search
- Path: library.erc.clarkson.edu!rpi!not-for-mail
- From: doug@monet.ads.com (Doug Morgan)
- Newsgroups: comp.lang.c++.moderated,comp.lang.c++,comp.os.ms-windows.programmer.misc
- Subject: Re: STL loops through a list with one element more than once! Why?
- Date: 2 Jan 1996 20:31:03 -0000
- Organization: Booz-Allen & Hamilton
- Sender: cppmods@netlab.cs.rpi.edu
- Approved: Dietmar.Kuehl@uni-konstanz.de
- Message-ID: <4cc4m7$9v8@netlab.cs.rpi.edu>
- References: <4c1n8o$2jn@netlab.cs.rpi.edu>
- NNTP-Posting-Host: netlab.cs.rpi.edu
-
- X-Original-Date: 02 Jan 1996 18:54:44 GMT
-
- In article <4c1n8o$2jn@netlab.cs.rpi.edu> Bowden Wise <wiseb@cs.rpi.edu> writes:
- >...
- > for (_itemIter = _itemList.begin();
- > _itemIter != _itemList.end();
- > _itemIter++)
- > {
- >...
- > _itemList.erase (_itemIter);
- > }
- > ...
- > Any ideas why the _itemIter != _itemList.end() test of the for
- > loop is failing? Anyone else encountered this?
-
- The erase() invalidates _itemIter. Continuing the loop is therefore
- invalid. Use _itemList.erase(_itemList.begin(), _itemList.end())
- instead.
-
- Doug
- ----------
- Doug Morgan TEL: (415) 960-7444 Booz-Allen & Hamilton, Inc.
- doug@ads.com (UNIX) FAX: (415) 960-7500 1500 Plymouth St.
- morgan_doug@bah.com (MS-Mail) Mountain View, CA 94043-1230
- ----------
-
- [ comp.lang.c++.moderated is a moderated newsgroup. Submit articles ]
- [ to <c++-submit@netlab.cs.rpi.edu>. The moderation policy can be ]
- [ retrieved from <http://netlab.cs.rpi.edu/~cppmods/guide.html>. ]
- [ Moderators can be reached at: c++-request@netlab.cs.rpi.edu. ]
-